<template>
  <div>
    <el-form :inline="true" :model="params" class="demo-form-inline">
      <el-form-item label="企业名称">
        <el-input v-model="params.plname" placeholder="企业名称"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-select
          v-model="params.plstate"
          placeholder="状态"
          style="width: 100px"
        >
          <el-option label="全部" value="0"></el-option>
          <el-option label="待审批" value="1"></el-option>
          <el-option label="已审批" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="plid" label="序号" width="120"> </el-table-column>
      <el-table-column prop="plname" label="企业名称" width="120">
      </el-table-column>
      <el-table-column prop="plnumber" label="社会信用代码" width="120">
      </el-table-column>
      <el-table-column prop="plmoney" label="注册资本" width="300">
      </el-table-column>
      <el-table-column prop="salesman" label="业务员" width="120">
      </el-table-column>
      <el-table-column prop="plstate" label="流程状态" width="120">
      </el-table-column>
      <el-table-column prop="pldate" label="任务开始时间" width="120">
      </el-table-column>
      <el-table-column v-if="this.ok" prop="bmid" label="bmid" width="120">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small"
            >查看</el-button
          >
          <el-button type="text" size="small" @click="onSubmit(scope.row)"
            >提交</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.pageIndex"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="this.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.pageTotal"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ok: false,
      params: {
        plname: "",
        plstate: null,
      },
      tableData: [
        {
          plid: "",
          plname: "",
          plnumber: "",
          plmoney: "",
          salesman: "",
          plstate: "",
          pldate: "",
          bmid: "",
        },
      ],
      pageIndex: 1,
      pageSize: 5,
      pageTotal: 0,
    };
  },
  created() {
    this.getAll();
  },
  methods: {
    onSubmit() {
      console.log(this.params.plstate);
      this.getAll();
    },
    getAll() {
      this.$axios
        .get("http://localhost:8082/preloan/select", {
          params: {
            plname: this.params.plname,
            plstate: this.params.plstate,
            pageIndex: this.pageIndex,
            pageSize: this.pageSize,
          },
        })
        .then((resp) => {
          console.log(resp.data.data.list);
          this.tableData = resp.data.data.list;
          for (var state in this.tableData) {
            if (this.tableData[state].plstate == 1) {
              this.tableData[state].plstate = "待审核";
            } else {
              this.tableData[state].plstate = "已提交";
            }
          }
          this.pageIndex = resp.data.data.pageNum;
          this.ppageSize = resp.data.data.size;
          this.pageTotal = resp.data.data.total;
        });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getAll();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getAll();
    },
    handleClick(row) {
      console.log(row);
      this.$router.push({ path: "/borrowDemand", query: { bmid: row.bmid,plname: row.plname,plid:row.plid } });
    },
    onSubmit(row) {
       
       
      this.$confirm("是否确认要提交进件申请？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios
            .post("http://localhost:8082/preloan/insert",{
              plid:row.plid,
              salesman:row.salesman,
              bmid:row.bmid
            })
            .then((resp) => {
              this.$message({
                type: "success",
                message: "提交成功!",
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消提交",
          });
        });
    },
  },
};
</script>

<style>
</style>